package com.zj.study.handle;

import com.zj.study.pojo.FinalResultVO;
import com.zj.study.pojo.RespStatusEnum;
import org.springframework.http.ResponseEntity;

/**
 * @author 赵赳
 * @since: 2021/8/6 9:17
 */
public interface ExceptionHandler {

  RespStatusEnum DEFAULT_STATUS = RespStatusEnum.INTERNAL_SERVICE_ERROR;

  RespStatusEnum CLIENT_BAD_PARAMETERS = RespStatusEnum.CLIENT_BAD_PARAMETERS;


  /**
   * 类型匹配
   *
   * @param clazz 类型
   * @return 匹配结果
   */
  boolean match(Class<?> clazz);

  /**
   * 异常处理
   *
   * @param throwException 异常对象
   * @return 返回响应配置对象
   */
  ResponseEntity<?> handler(Throwable throwException);

  /**
   * 默认响应处理 默认状态：200
   *
   * @param basicResult 响应对象
   * @return 返回响应配置对象
   */
  default ResponseEntity<?> response(FinalResultVO<?> basicResult) {
    return ResponseEntity.ok().body(basicResult);
  }

}